import * as THREE from 'three';
import Experience from '../class/Experience';
import { EventEmitter } from 'events'
export default class CreateModel extends EventEmitter {


    constructor() {
        super();
        this.experience = new Experience();

        this.experience.assets.on('ready', () => {
            this.items = this.experience.assets.items;
            this.setModel();
            // this.setMark();
        })

        // this.setTexture();

        // this.loadDown = false;
    }

    setTexture() {
        // this.texture = this.experience.textureLoader.load('./model/touming.png');
        // this.texture.center.set(0.5, 0.5);
        // this.texture.rotation = -Math.PI
        // this.texture.flipY = false;
        // this.texture.encoding = THREE.sRGBEncoding
        // this.bakeMaterial = new THREE.MeshBasicMaterial({ map: this.texture });
    }

    setModel() {
        const wallGlb = this.items['wallGlb'];
        const mesh = wallGlb.children[0].children[0].children[0]
        mesh.material.color = new THREE.Color('#3963bc');
        this.experience.scene.add(wallGlb)
        this.experience.box3.moveToCenter(wallGlb)
        wallGlb.scale.multiplyScalar(1)
        wallGlb.scale.y = 2
        wallGlb.position.y =0.07

        // this.experience.gltfLoader.load(
        //     './model/wallreverse.glb',
        //     gltf => {
        //         console.log(gltf)
        //         gltf.scene.traverse((child) => {

        // if (child.isMesh) {
        // console.log(child);
        // const material = new THREE.MeshStandardMaterial({
        //     map: this.texture,
        //     color: new THREE.Color('#FB821F').multiplyScalar(0.5),
        //     emissive: new THREE.Color('#FB821F').multiplyScalar(0.5),
        //     roughness: 0.438,
        //     metalness: 0,
        //     depthWrite: true,
        //     transparent: true,
        //     opacity: 1,
        //     side: THREE.DoubleSide
        // });
        // child.material.color = new THREE.Color('#3963bc');
        // }

        // })
        // const mesh = gltf.scene.children[0].children[0].children[0]
        // mesh.material = this.bakeMaterial

        // this.loadDown = true;
        // }
        // )
    }
    setMark() {
        const markGlb = this.items['markGlb'];
        const markUpMesh = markGlb.children.find((child) => child.name === "mark_up")
        const markDownMesh = markGlb.children.find((child) => child.name === "mark_down")
        const poleLightM = new THREE.MeshBasicMaterial({ color: 0x3963bc })

        markDownMesh.material = poleLightM
        markUpMesh.material.color = new THREE.Color('#3963bc');

        this.experience.scene.add(markGlb)
        markGlb.scale.multiplyScalar(0.1)
        markGlb.scale.y = 0.08
        markGlb.position.y = 0.2

    }

    update() {


    }
}


